import sys
from collections import Counter

class Card:
    def __init__(self, color, number):
        self.color = color
        self.number = number

    def __repr__(self):
        return '<Card: color=%s, number=%s>' % (self.color, self.number)


class Solution:
    def count_scores(self, cards):
        if self.type1(cards):
            return 15000
        if self.type2(cards):
            return 8000
        if self.type3(cards):
            return 300
        if self.type4(cards):
            return 150
        if self.type5(cards):
            return 40
        if self.type6(cards):
            return 20
        if self.type7(cards):
            return 6
        if self.type8(cards):
            return 4
        if self.type9(cards):
            return 2
        return 1


    def type1(self, cards):
        if len(cards) != 5:
            return False
        # type 1: same number
        for c in cards:
            if c.number != cards[0].number:
                return False
        return True

    def type2(self, cards):
        if len(cards) != 5:
            return False
        # type 2: same color, number consecutive
        for c in cards:
            if c.color != cards[0].color:
                return False
        sorted_cards = sorted(cards, key=lambda x: x.number)
        # print(sorted_cards)
        for i, j in zip(sorted_cards, sorted_cards[1:]):
            if i.number + 1 != j.number:
                return False
        return True

    def type3(self, cards):
        if len(cards) != 5:
            return False
        # type 3: same color
        for c in cards:
            if c.color != cards[0].color:
                return False
        return True

    def type4(self, cards):
        cnt = Counter(sorted([c.number for c in cards]))
        for k in cnt:
            if cnt[k] == 4:
                return True
        return False

    def type5(self, cards):
        cnt = Counter(sorted([c.number for c in cards]))
        res1, res2 = False, False
        for k in cnt:
            if cnt[k] == 3:
                res1 = True
            if cnt[k] == 2:
                res2 = True
        return res1 and res2

    def type6(self, cards):
        sorted_cards = sorted(cards, key=lambda x: x.number)
        # print(sorted_cards)
        for i, j in zip(sorted_cards, sorted_cards[1:]):
            if i.number + 1 != j.number:
                return False
        return True

    def type7(self, cards):
        cnt = Counter(sorted([c.number for c in cards]))
        for k in cnt:
            if cnt[k] == 3:
                return True
        return False


    def type8(self, cards):
        cnt = Counter(sorted([c.number for c in cards]))
        nums = [k for k in cnt if cnt[k] == 2]
        return len(nums) == 2

    def type9(self, cards):
        cnt = Counter(sorted([c.number for c in cards]))
        for k in cnt:
            if cnt[k] == 3:
                return True
        return False


if __name__ == '__main__':
    fp = sys.stdin
    # fp = open('./netease2.in')
    M = int(fp.readline())
    s = Solution()
    # [M] data groups
    for i in range(M):
        N = int(fp.readline())
        numbers = [int(j) for j in fp.readline().strip().split()]
        colors = [j for j in fp.readline().strip().split()]
        assert len(colors) == N
        cards = [Card(c, n) for c, n in zip(colors, numbers)]
        print(s.count_scores(cards))
        
